#ifndef NESDISPLAYGL_H
#define NESDISPLAYGL_H
#include <QTimer>
#include <QWheelEvent>
#include <QMenu>
#include <QOpenGLWidget>
#include <QOpenGLShaderProgram>
#include <QOpenGLFunctions_4_5_Core>




class NESDisplayGL:public QOpenGLWidget,private QOpenGLFunctions_4_5_Core{
    Q_OBJECT
  public:

    void InputFrame(uint32_t* ColorArray);
    void SetIsDisplay(bool IsDisplay);
    QString GetOpenGLVersion();

    explicit NESDisplayGL(QWidget* parent = nullptr);
    ~NESDisplayGL();

  protected:

    void mousePressEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent* event);
    void mouseMoveEvent(QMouseEvent* event);
    void wheelEvent(QWheelEvent* event);

    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();

  private:
    int mouseRightPress_X;
    int mouseRightPress_Y;
    int mouseMove_X;
    int mouseMove_Y;

  signals:

  private:

    QMenu* RightKeyMenu;
    QAction* action_Reset;

    bool InitDone;
    bool IsDisplay;
    bool IsMovability;
    QString OpenGLVersion;

    int FrameWidth;
    int FrameHeight;

    static const GLfloat DefaultVertex[];
    GLfloat* Vertex;
    int VertexSize;
    static const GLuint DefaultIndices[];
    GLuint* Indices;
    int IndicesSize;
    GLuint VBO;
    GLuint VAO;
    GLuint EBO;
    QOpenGLShaderProgram shaderProgram;
    GLuint NES_Texture;
    uint32_t* NES_Texture_SrcBuffer;
    GLuint Logo_Texture;
    uint32_t* Logo_Texture_SrcBuffer;
    bool M_View_IsUpdate;
    QMatrix4x4 M_View;
    bool M_Model_L_IsUpdate;
    QMatrix4x4 M_Model_L;
    bool M_Model_R_IsUpdate;
    QMatrix4x4 M_Model_R;



    
    void action_Reset_Click();
    
    void M_View_Reset();
    void M_Model_L_Reset();
    void M_Model_R_Reset();


    Q_INVOKABLE void InitError();
    Q_INVOKABLE void Error(QString s);

};




#endif // NESDISPLAYGL_H
